/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.p10.miage.gestionnote.form;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author charleshenzel
 */
public class ECAjouterCommentaireEtudiantActionForm extends org.apache.struts.action.ActionForm {
    
    private int idec; //caché
    private int idp; //caché
    private int sizeListeEtudiant; // caché
    private Map<String,String> HashMap ;
    
    public int getIdec() {
        return idec;
    }

    public void setIdec(int idec) {
        this.idec = idec;
    }

    public int getIdp() {
        return idp;
    }

    public void setIdp(int idp) {
        this.idp = idp;
    }

    public Map<String, String> getHashMap() {
        return HashMap;
    }

    public void setHashMap(Map<String, String> HashMap) {
        this.HashMap = HashMap;
    }

    public int getSizeListeEtudiant() {
        return sizeListeEtudiant;
    }

    public void setSizeListeEtudiant(int sizeListeEtudiant) {
        this.sizeListeEtudiant = sizeListeEtudiant;
    }

    /**
     *
     */
    public ECAjouterCommentaireEtudiantActionForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        Map<String,String> HashMapTmp = new HashMap<String,String>();
        for(int i=0;i<sizeListeEtudiant;i++)
        {
            try {
                 String commentaire = request.getParameter("commentaire"+i);
                 // Bizare selon l'encoding serveur il faudra surement commenter
                 commentaire = new String(commentaire.getBytes("iso-8859-1"), "UTF-8");
                 HashMapTmp.put(request.getParameter("idEtudiant"+i),commentaire);
            } catch (UnsupportedEncodingException ex) {
                Logger.getLogger(ECAjouterCommentaireEtudiantActionForm.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        setHashMap(HashMapTmp);
        
        return errors;
    }
}
